/*
 * function.cpp
 *
 *   Created on: 2010-4-1     
 *  Description: 
 *    Copyright: 2010 @ ICT Li Heyuan
 */

#include "function.h"
#include <json-rpc-e/client/TcpClient.h>
#include <json-rpc-e/json_cpp/json.h>

bool test_a_add_b(std::string ip, unsigned int port)
{
	TcpClient client(ip, port);
	client.setEncrypt(false);
	client.setCloseFirst(false);

	//随机生成a和b
	int a, b;
	a = random() % 100;
	b = random() % 100;

	Json::Value param;
	param.append(Json::Value(a));
	param.append(Json::Value(b));

	Json::Value ret;
	if (client.call("add", param, ret))
	{
		if (ret.asInt() == (a + b))
		{
			return true;
		}
		else
		{
			printf("error %d+%d=%d ?\n", a, b, ret.asInt());
			return false;
		}
	}
	else
	{
		Json::FastWriter writer;
		string err = writer.write(ret);
		printf("error %s.\n", err.c_str());
		return false;
	}

}
